/**
 * Toggle widget creator.
 * 
 * A toggle widget contains two views from which only one is shown at a time.
 */

function ToggleWidget(options) {
	if(!options) options = {};
	if(!options.id) options.id = Widget.uid();

	var that = Widget(options);
	
	function viewId(index) {
		return options.id + "-view-" + index;
	}

	function getView(index) {
		return $("#" + viewId(index));
	}

	that.getHtml = function() {
		return sprintf('<div id="%s"><div id="%s"></div><div id="%s" style="display: none;"></div></div>', options.id, viewId(0), viewId(1));
	};

	that.setContent = function(index, content) {
		getView(index).html(content);
	};
	
	that.showContent = function(index) {
		mwl.hide("#" + viewId((index + 1)%2));
		mwl.show("#" + viewId(index));
	};
	
	that.showContentMwl = function(index) {
		return sprintf("mwl.hide('#%s');mwl.show('#%s');", viewId((index + 1)%2), viewId(index));
	};
	
	return that;
}
